import { Script, Vector3 } from "oasis-engine";
import { OrbitControl } from "@oasis-engine/controls";
import { Tween } from "@tweenjs/tween.js";

const target = new Vector3(0, 0, 0);
export class CameraScript extends Script {
  reset() {
    this.entity.transform.setPosition(-100, 100, 100);
    this.entity.transform.lookAt(target);
    // this.entity.addComponent(OrbitControl);
  }

  updateCameraPos(nextTablePosition: Vector3, rolePosition: Vector3) {
    new Tween(this.entity.transform.position)
      .to(
        {
          x: (nextTablePosition.x + rolePosition.x) / 2 - 100,
          y: (nextTablePosition.y + rolePosition.y) / 2 + 100,
          z: (nextTablePosition.z + rolePosition.z) / 2 + 100,
        },
        800
      )
      .start()
      .onUpdate(() => {
        const pos = this.entity.transform.position;
        this.entity.transform.position = pos;
      });
  }
}
